import { Component, OnInit,NgModule } from '@angular/core';
import{ FormsModule,NgForm }from'@angular/forms';
import {MdDialog,MdDialogModule} from '@angular/material';
import {UserService}from './user.service';
//import{Service}from'./service';
import {User,Picture}from './user';

import { PictrueComponent } from '../pictrue/pictrue.component';
@Component({
  selector: 'app-sign',
  templateUrl: './sign.component.html',
  styleUrls: ['./sign.component.css']
})
export class SignComponent{

  user:User;
  picture:Picture;
  randomNum:number;
  telNum11:number;
  input1:any;
  constructor(
     //声明变量为UserSerice类型
    private userService: UserService,
    private dialog:MdDialog,
  ) {
    //console.log(dialog);
  }
  ngOnInit() {
        this.randomNum = Math.random()*10+1;
        //this.randomNum = 1
  }
  //验证用户是否存在      用来数据传输
   userGet(){
       this.userService.userGet(this.user);
    }
  openDialog() {
      console.log(this.dialog);
      //弹出一个组件
       this.dialog.open(PictrueComponent);
  }

  //获取图片验证码
  imgGet(){
     this.userService.imgGet(this.picture);
  }
   //获得input按钮中value的长度
   keyupHandler1(event:any) {
          this.input1 = event.target.value.length;
   }
   //当用户输入的11位手机号之后发送验证请求
   telGet(){
     if(this.input1 == 11){
         this.userService.userGet(this.user);
     }
   }

//把获取验证码图片和点击弹窗放到一起
  userPostAddUser(){
    //this.telGet(),
    //this.userGet(),
    //this.openDialog(),
    this.imgGet()
  }

//验证表单
nameErrorMsg:any;
  logForm(theForm: NgForm) {
    if (theForm.invalid) {
        if (theForm.controls['name'].errors) {
            this.nameErrorMsg = 'name error:' + JSON.stringify(theForm.controls['name'].errors);
        } else {
            this.nameErrorMsg = null;
        }
    }
    console.log(theForm.value);
}

}

/*
@Component({
  selector: 'PictrueComponent',
 templateUrl: '../pictrue/pictrue.component.html',
})
export class PictrueComponent {}
*/
